package office.excel.poi.test.expexcel;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;


/**
 * excel 导出Action
 * @author Administrator
 *
 */
public class ExpexcelAction   {
      /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void  expExcelCommonByArray() throws Exception
	{
	/*   HttpServletResponse response = ServletActionContext.getResponse();
	   ExpExcel exp = new ExpExcel(Struts2Utils.getRequest());
	   exp.ExcelTemplatePath="\\upload\\excelTemplate\\";
	   exp.NewExcelPath="\\upload\\";
	   String sPath = exp.expExcelByJsonArray();
	   response.setCharacterEncoding("utf-8");
	   PrintWriter  pw =response.getWriter();
	   JSONObject o = new JSONObject();
	   o.put("OK",1);
	   o.put("name",URLEncoder.encode(exp.NewExcelName, "UTF-8"));
	   pw.write(o.toString());
	   pw.flush();
	   pw.close();*/
	}
	
	public String downloadXls() throws UnsupportedEncodingException
	{
	/*	HttpServletResponse response = ServletActionContext.getResponse();
		String name = Struts2Utils.getRequest().getParameter("name");
		String sPath = LoadExcel.basePath+"\\upload\\"+name;
		 try {
			   File file = new File(sPath);
				InputStream fis = new BufferedInputStream(
						new FileInputStream(sPath));
				byte buffer[] = new byte[fis.available()];
				fis.read(buffer);
				fis.close();
				response.reset();

				OutputStream toClient = new BufferedOutputStream(
						response.getOutputStream());
				response.setContentType("application/x-download");
				response.setCharacterEncoding("UTF-8");
			     //解决中文乱码
				name = name.substring(13);
				name = URLEncoder.encode(name, "UTF-8");
			    response.setHeader("Content-Disposition","attachment;filename="+new String
			(name.getBytes(),"UTF-8"));    
				
				toClient.write(buffer);
				toClient.flush();
				toClient.close();
				file.delete();
				file.delete();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		 return null;*/
		 return null;
	}
}
